package com.cash.channel.svc.service.common;

import com.cash.channel.svc.service.base.BankList;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cash.channel.api.constant.Constant;
import com.cash.channel.api.model.ApiRequestModel;
import com.cash.channel.api.model.ApiResponseModel;
import com.cash.channel.api.model.request.BankListRequest;
import com.cash.channel.api.model.response.BankListResponse;
import geex.payment.model.ll.LlBankInfoModel;
import geex.payment.model.pojo.ResponseResult;
import geex.payment.service.QueryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service(Constant.CHANNEL.COMMON+ Constant.SERVICE.支持银行列表)
public class CommonBankList implements BankList {

    @Resource
    private QueryService queryService;

    @Override
    public ApiResponseModel<BankListResponse> getBankList(ApiRequestModel apiRequestModel) {
        BankListRequest bankListRequest = JSON.parseObject(apiRequestModel.getData(), BankListRequest.class);
        BankListResponse bankListResponse = new BankListResponse();
        String uid = bankListRequest.getUserId();
        ResponseResult responseResult = queryService.supportBankQuery(bankType);
        JSONObject jsonObject = (JSONObject) JSON.toJSON(responseResult.getData());
        JSONArray bankJsonArray = jsonObject.getJSONArray("bankList");
        for (Object bankObject : bankJsonArray) {
            LlBankInfoModel bankInfoModel = JSON.toJavaObject((JSON) bankObject, LlBankInfoModel.class);
            bankListResponse.addBank(bankInfoModel.getBankCode(), bankInfoModel.getIconPath(), bankInfoModel.getBankName());
        }
        return new ApiResponseModel<>(true, 0, "", bankListResponse);
    }

}
